<?php
namespace Admin\Controller;
use Admin\Controller\VerifyController;
use Common\Model\AdminModel;
class LoginController extends VerifyController{
	///登录首页
	public function index(){
		$this -> display();
	}
	///验证登录
	public function checkLogin(){
		$code     = I("code",null);
		$username = I("username",null);
		$password = I("password",null);
		$M_Admin = new AdminModel();
		if(empty($code)){
			$data['status'] = -1;
	    	$data['info']   = '验证码不能为空';
	    	$this -> ajaxReturn($data);
		}
		$res = $this->checkVerify($code);
		if(!$res){
			$data['status'] = -2;
	    	$data['info']   = '验证码错误';
	    	$this -> ajaxReturn($data);
		}
		if(empty($username)){
			$data['status'] = -3;
	    	$data['info']   = '用户名不能为空';
	    	$this -> ajaxReturn($data);
		}
		if(empty($password)){
			$data['status'] = -4;
	    	$data['info']   = '密码不能为空';
	    	$this -> ajaxReturn($data);
		}
		$where['username'] = $username;
		$where['password'] = md5($password);
		$userInfo = $M_Admin ->getAdminList($where);
		session("uid",$userInfo[0]['id']);
	    if(empty($userInfo)){
	    	$data['status'] = -5;
	    	$data['info']   = '用户名或密码错误';
	    	$this -> ajaxReturn($data);
	    }
	    $data['status'] = 1;
	    $data['info']   = '登录成功';
	    $this -> ajaxReturn($data);
	}
	///退出
	public function outLogin(){
		session(null);
		if(session('?uid')){
			$data['status'] = -1;
			$data['info']   = '无法退出';
			$this -> ajaxReturn($data);
		}
		$data['status'] = 1;
		$data['info']   = '安全退出';
		$this -> ajaxReturn($data);
	}
}